package dataserver.controller.vo;

import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;

import java.io.Serializable;
import java.util.List;

/**
 * 返回分页JSON
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonPropertyOrder({ "code", "message", "retResult","pageNum", "pageSize", "total", "pages" })
public class ResultPageInfo<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	private Integer code = 200;
	private String message = "成功";
    /**
     * 第几页
     */
    private Integer pageNum;
    /**
     * 每页条数
     */
    private Integer pageSize;
    /**
     * 总条数
     */
    private Long total;
    /**
     * 总页数
     */
    private Integer pages;
    /**
     * 分页对象集合
     */
    private List<T> data;
    /**
     * 是否首页
     */
    private Boolean isFirstPage;
    /**
     * 是否最后一页
     */
    private Boolean isLastPage;
    public ResultPageInfo(Integer code,String message,Page<T> t) {
        this.code = code;
        this.message = message;
        this.pageNum = t.getNumber() + 1;
        this.pageSize = t.getSize();
        this.total = t.getTotalElements();
        this.pages = t.getTotalPages();
        this.isFirstPage = t.isFirst();
        this.isLastPage = t.isLast();
        this.data = t.getContent();
    }

	public ResultPageInfo(Page<T> t) {
        this.pageNum = t.getNumber() + 1;
        this.pageSize = t.getSize();
        this.total = t.getTotalElements();
        this.pages = t.getTotalPages();
        this.isFirstPage = t.isFirst();
        this.isLastPage = t.isLast();
        this.data = t.getContent();
    }

}
